# 1、对之前的脚本生成测试报告
# 2、配置ini文件
# 3、练习数据驱动和rerun、makr一些内置方法

import pytest
import requests
import allure,uuid
@allure.feature("用户分组")
class TestUser():
    @pytest.fixture(scope='function',autouse=True)
    def setup_teardown(self):
        res = requests.post(url = project_url + "/adminapi/login",json = {"account":"admin","pwd":"123456","imgcode":"a"})
        self.token = "Bearer " + str(res.json()['data']['token'])
        assert res.status_code == 200
        assert res.json()['msg'] == 'ok'
        yield
        print("用例执行结束")
    @allure.story("添加分组")
    def test_user(self):
        # ==新增==
        self.uuid = str(uuid.uuid4()).split("-")[0]
        res = requests.post(url = project_url + "/adminapi/app/wechat/speechcraft",headers = {"Content-Type":"application/json;charset=UTF-8","Authori-zation":self.token}
                      ,json = {"cate_id":"","title":"test01","message":"test"+self.uuid,"sort":0})
        assert res.json()['msg'] == "创建话术成功"
        assert res.status_code == 200

        #==查询==
        res = requests.get(project_url + "/adminapi/app/wechat/speechcraft?page=1&limit=15&cate_id=",headers={"Authori-zation":self.token})
        for i in res.json()['data']['list']:
            if i['message'] == "test"+self.uuid:
                self.id = i['id']

        #== 删除==
        res = requests.delete(project_url +"/adminapi/app/wechat/speechcraft/"+str(self.id),headers={"Authori-zation":self.token})
        assert res.json()['msg'] == "删除成功"
        assert res.status_code == 200

if __name__ == '__main__':
    pytest.main()